/**
 * 财务相关路由
 */
const express = require('express');
const router = express.Router();
const financeController = require('../controllers/financeController');
const authenticate = require('../middleware/auth');
const validator = require('../middleware/validator');

// 所有财务路由都需要认证
router.use(authenticate);

// 获取财务记录列表
router.get('/', financeController.getRecords);

// 获取财务统计
router.get('/statistics', financeController.getStatistics);

// 获取单条财务记录
router.get('/:id', validator.validateIdParam(), financeController.getRecord);

// 创建财务记录
router.post(
  '/',
  validator.validateRequired(['amount', 'type']),
  validator.validateDates(['record_time']),
  financeController.createRecord
);

// 更新财务记录
router.put(
  '/:id',
  validator.validateIdParam(),
  validator.validateDates(['record_time']),
  financeController.updateRecord
);

// 删除财务记录
router.delete('/:id', validator.validateIdParam(), financeController.deleteRecord);

// 获取财务分类
router.get('/categories', financeController.getCategories);

// 创建财务分类
router.post(
  '/categories',
  validator.validateRequired(['name', 'type']),
  financeController.createCategory
);

module.exports = router; 